using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimeSheetBLL;

namespace TimeSheet.Protected
{
    /// <summary>
    /// Summary description for ActivityReport.
    /// </summary>
    public class ActivityReport : Page
    {
        protected Label lblTitle;
        protected Label lblTotalHours;
        protected DataGrid dgNonBillable;
        protected Label lblDateRange;

        private void Page_Load(object sender, EventArgs e)
        {
            TimeSheetBLL.Activity act = GetActivity();
            lblTitle.Text = "Activity Report for <u>" + act.ActivityName + "</u>";
            lblTotalHours.Text =
                act.GetTotalHoursByDate(GetFromDate(), GetToDate()).ToString("F");
            lblDateRange.Text = "From " + GetFromDate().ToShortDateString() + " to " +
                                GetToDate().ToShortDateString();
            BindAllHours(act, GetFromDate(), GetToDate());
        }

        private void BindAllHours(TimeSheetBLL.Activity act, DateTime from, DateTime to)
        {
            DataTable dt = act.GetActivityHoursByDate(GetFromDate(), GetToDate());
            dgNonBillable.DataSource = dt;
            dgNonBillable.DataBind();
        }

        private DateTime GetFromDate()
        {
            return Convert.ToDateTime(Server.UrlDecode(Request["from"]));
        }

        private DateTime GetToDate()
        {
            return Convert.ToDateTime(Server.UrlDecode(Request["to"]));
        }

        private TimeSheetBLL.Activity GetActivity()
        {
            TimeSheetBLL.Activity act = new TimeSheetBLL.Activity();
            act.ID = Convert.ToInt64(Server.UrlDecode(Request["id"]));
            BrokerFactory.Fill(act);
            return act;
        }

        #region Web Form Designer generated code

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion
    }
}